package com.czk.scala.chapter02

import com.czk.scala.chapter01.Student

/**
 * byte范围 -128-127 超过此值会报错
 *
 * @Author:ChenZhangKun
 * @Date: 2021/12/7 10:33
 */
object Test_05_DataByte {
  def main(args: Array[String]): Unit = {
    val a1: Byte = 127
    //
    val a2: Byte = -128

    val b1: Byte = 10
    // 类型推断
    val b2: Byte = (10 + 20)
    println(b2)
    // 强制转换 因为b1不确定性，需要运行时才知道类型
    val b3: Byte = (b1 + 20).toByte
    println(b3)

    val d1: Double = 1.25

    val f1: Float = 1.26f

    println(d1)
    println(f1)

    val c1: Char = 'a'
    println(c1)
    println(c1.toInt)

    val c2: Char = '9'
    println(c2)
    val i: Int = c2
    println(i)

    val c3: Char = '\t'
    val c4: Char = '\n'
    // 制表符的输出
    println("abc" + c3 + "def")
    println("abc" + c4 + "def")

    // 转义字符
    val c5 = '\\' // 表示\自身
    val c6 = '\"' // 表示"
    println("abc" + c5 + "def")
    println("abc" + c6 + "def")

    // bollean
    val isTrue: Boolean = true
    val isFalse: Boolean = false
    println(isFalse)
    println(isTrue)

    // 空类型
    // 空值Unit
    def m1(): Unit = {
      println("m1被执行")
    }

    val a = m1()
    // 空括号()
    println(a)

    // 空引用Null
    var student: Student = new Student("calice", 30)
    // 引用类型都可以赋值为null
    student = null
    println(student)

    // nothing->所有类型的子类
    // any->所有引用类型的超类
    def m2(n: Int): Nothing = {
      throw new NullPointerException
    }

/*
    val b = m2(1)
    println(b)
*/

    def m3(n: Int): Int = {
      if (n == 0)
        throw new NullPointerException
      else
        return n
    }

    val m4: Int = m3(1)
    println(m4)
  }
}
